/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Principal;

import javax.swing.filechooser.*;
import java.io.File;

public class Filtro extends FileFilter{

    private String extension,description;
     
     public Filtro(String extension, String description){
         this.extension = extension.toLowerCase();
         this.description = description;
     }
    
      public String getExtension(File f) {
	if(f != null) {
	    String filename = f.getName();
	    int i = filename.lastIndexOf('.');
	    if(i>0 && i<filename.length()-1) {
		return filename.substring(i+1).toLowerCase();
	    };
	}
	return null;
    }
    
    public boolean accept(File f) {
	if(f != null) {
	    if(f.isDirectory()) {
		return true;
	    }
	    String extension = getExtension(f);
	    if(extension != null && extension.equals(this.extension)) {
		return true;
	    };
	}
	return false;
    }
    
    public String getDescription(){
        return this.description;
    }

    }
